package com.roubsite.cloud.filter;

import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;

@Component
public class CorsFilter implements WebFilter {

	@Override
	public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
		ServerHttpResponse response = exchange.getResponse();
		HttpHeaders httpHeaders = response.getHeaders();
		httpHeaders.set("Access-Control-Allow-Origin", "*");
		httpHeaders.set("Access-Control-Allow-Methods", "*");
		httpHeaders.set("Access-Control-Max-Age", "3600");
		httpHeaders.set("Access-Control-Allow-Headers", "*");
		httpHeaders.set("Access-Control-Allow-Credentials", "true");
		return chain.filter(exchange);
	}
}
